package com.sylli.oeuf.server.object.transferable;

import com.sylli.oeuf.server.game.logic.BattleActor;
import com.sylli.oeuf.server.game.logic.BattleActorSource;
import com.sylli.oeuf.server.game.logic.Plan;

public class WrappedCharacterInfoTO extends BasedTO implements BattleActorSource {

	/**
	 * 
	 */
	private static final long serialVersionUID = 6652453887091016980L;
	
	private CharacterGeneralInfoTO generalInfo;
	
	private CharacterPostDataTO postData;
	
	public WrappedCharacterInfoTO() {
		// for flex
	}
	
	public WrappedCharacterInfoTO(CharacterGeneralInfoTO g, CharacterPostDataTO p) {
		generalInfo = g;
		postData = p;
	}
	
	@Override
	public boolean equals(Object obj) {
		if (obj instanceof WrappedCharacterInfoTO) {
			WrappedCharacterInfoTO w = (WrappedCharacterInfoTO) obj;
			return w.generalInfo.equals(generalInfo)
				&& w.postData.equals(postData);
		}
		return false;
	}

	@Override
	public String toString() {
		return "WrappedCharacterInfo: \ngeneralInfo=" + generalInfo
			+ ", \npostData=" + postData;
	}

	public CharacterGeneralInfoTO getGeneralInfo() {
		return generalInfo;
	}

	public void setGeneralInfo(CharacterGeneralInfoTO generalInfo) {
		this.generalInfo = generalInfo;
	}

	public CharacterPostDataTO getPostData() {
		return postData;
	}

	public void setPostData(CharacterPostDataTO postData) {
		this.postData = postData;
	}

	@Override
	public void snapback(BattleActor actor) {
		postData.setCurrentHp(actor.getCurrHealth());
		postData.setCurrentMp(actor.getCurrMana());
	}

	@Override
	public Plan findPlan(int id) {
		if (getAvailablePlanCount()==0)
			return null;
		StrategyTO st = getGeneralInfo().findStrategy(id);
		if (st == null) {
			return null;
		} else {
			return st.toGameLogicObject();
		}
	}

	@Override
	public int getAvailablePlanCount() {
		return getGeneralInfo().getStrategyBundle().getBundle().size();
	}

}
